package com.gitee.ly.ymorm.jsonserializer;

import java.util.function.Function;

/**
 * YmOrmJsonSerializer
 *
 * @author ly
 **/
public class YmOrmJsonSerializer {
    private Function<Object, String> jsonSerialHandle = null;

    public YmOrmJsonSerializer() {
    }

    public YmOrmJsonSerializer(Function<Object, String> jsonSerialHandle) {
        this.jsonSerialHandle = jsonSerialHandle;
    }

    /**
     * 设置json序列化处理
     */
    public void setJsonSerialHandle(Function<Object, String> setJsonSerialHandle) {
        jsonSerialHandle = setJsonSerialHandle;
    }

    /**
     * json序列化
     */
    public String getJsonSerial(Object data) {
        if (jsonSerialHandle != null) {
            return jsonSerialHandle.apply(data);
        } else {
            return data == null ? null : data.toString();
        }
    }

}
